package com.itheima.leetcode.od.c.dynamicprogramming;

import java.util.Arrays;
import java.util.Scanner;

/**
 * <h3>Wonderland游乐园</h3>
 */
public class Wonderland {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] costs = Arrays.stream(in.nextLine().split(" "))
                .mapToInt(Integer::parseInt)
                .toArray();
        int[] days = Arrays.stream(in.nextLine().split(" "))
                .mapToInt(Integer::parseInt)
                .toArray();

        int[] dp = new int[365 + 1];
        for (int i = 0; i < 365 + 1; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[0] = 0;
        int j = 0;
        for (int i = 1; i <= 365; i++) {
            if (j < days.length && i == days[j]) {
                dp[i] = Math.min(dp[i], dp[Math.max(0, i - 1)] + costs[0]);
                dp[i] = Math.min(dp[i], dp[Math.max(0, i - 3)] + costs[1]);
                dp[i] = Math.min(dp[i], dp[Math.max(0, i - 7)] + costs[2]);
                dp[i] = Math.min(dp[i], dp[Math.max(0, i - 30)] + costs[3]);
                j++;
            } else {
                dp[i] = dp[i - 1];
            }
        }

        System.out.println(dp[365]);
    }
}